package com.hnqcgc.sgzShopping.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DbImpl implements IDb {
   private String URL="jdbc:mysql://localhost:3306/dujiaoshou?useSSL=false&" +
           "serverTimezone=Hongkong&characterEncoding=utf-8&autoReconnect=true";
   private String USERNAME="root";
   private String PASSWORD="123456";
    public DbImpl() {
        //第一步：加载驱动
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
    @Override
    public Connection getConn() throws SQLException {
        Connection conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
        return conn;
    }
    public static void main(String[] args) {
        try {
            Connection conn = new DbImpl().getConn();
            System.out.println(conn.isClosed());
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
